(*
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *)

open! IStd

(** Datastructure for polymorphic getters of record fields *)
type 'r t

type 'r sub = S : ('r, 'f) Field.t * 'f t -> 'r sub

type ('r, 'a) user = {f: 'f. string -> ('r -> 'f) -> 'a} [@@unboxed]

val make : ?subfields:'r sub list -> ((_, 'r, 'r t) Field.user -> 'r t list) -> 'r t
(**
  Pass [Fields.map_poly] generated by [@@deriving fields] for the record ['r] you are interested
  in to get the polymorphic getters of the fields of ['r].
  A dummy field "ALL" is added too.

  Subfields appearing in [subfields] will be added too.
  Each subfield is specified by [S (field, poly_fields)] where [field] is the corresponding
  [Field.t] value (generated by [@@deriving fields]) and [poly_fields] is the result of this
  function for the field record type.
*)

val map : 'r t -> ('r, 'a) user -> 'a list
(**
  [map r f] maps each field of [r] with the function [f].
  [f] is called with two arguments: the name and the getter of the field.
*)
